package com.augurit.common.system.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.base.extmodel.IconMultiSelect;
import com.augurit.common.entity.AcMenu;
import com.augurit.common.entity.AcUserShortcut;
import com.augurit.common.system.util.OrgUtils;
import com.augurit.common.system.web.org.form.AcUserShortcutForm;

public class AcUserShortcutConverter {

	public static AcUserShortcutForm convertToForm(AcUserShortcut entity){
		if(entity != null){
			AcUserShortcutForm form = new AcUserShortcutForm();

			form.setUsId(entity.getUsId());
			form.setUserId(entity.getUserId());
			form.setMenuId(entity.getMenuId());
			form.setSortNo(entity.getSortNo());
			
			return form;
		}else
			return null;
	}
	
	/**
	 * 通过shortcut和menu实体对象获得转换过的shortcutForm对象
	 * @param shortcut 快捷菜单实体对象
	 * @param menu 菜单实体对象
	 * @return shortcutForm对象
	 */
	public static AcUserShortcutForm convertToForm(AcUserShortcut shortcut, AcMenu menu){
		AcUserShortcutForm form = convertToForm(shortcut);
		
		form.setMenuCode(menu.getMenuCode());
		form.setMenuLevel(menu.getMenuLevel().toString());
		form.setIsLeaf(menu.getIsLeaf());
		form.setIsActive(menu.getIsActive());
		form.setMenuName(menu.getMenuName());
		form.setMenuDesc(menu.getMenuDesc());
		
		form.setMenuUrl(OrgUtils.getMenuUrl(menu.getMenuUrl(), true));
		form.setSmallImgPath(OrgUtils.getImgPath(menu.getSmallImgPath(), true));
		form.setMiddleImgPath(OrgUtils.getImgPath(menu.getMiddleImgPath(), true));
		form.setBigImgPath(OrgUtils.getImgPath(menu.getBigImgPath(), true));
		
		return form;
	}
	
	public static List<AcUserShortcutForm> convertToFormList(List<AcUserShortcut> list){
		if(list != null && list.size() > 0){
			List<AcUserShortcutForm> result = new ArrayList();
			
			for(AcUserShortcut entity:list){
				AcUserShortcutForm form = convertToForm(entity);
				result.add(form);
			}
			
			return result;
		}
		return null;
	}
	
	public static List<IconMultiSelect> convertToBasicCombo(List<AcUserShortcutForm> list, boolean allowBlank){
		List<IconMultiSelect> result = new ArrayList();
		
		if(allowBlank)
			result.add(IconMultiSelect.getBlankItem());
		
		if(list != null && list.size() > 0){
			for(AcUserShortcutForm form : list){
				IconMultiSelect combo = new IconMultiSelect();
				combo.setText(form.getMenuName());
				combo.setValue(form.getMenuId().toString());
				combo.setIcon(form.getSmallImgPath());
				result.add(combo);
			}
		}
		
		return result;
	}
	
	/**
	 * 获取快捷菜单form对象列表 
	 * @param tempList 包含快捷菜单、菜单实体对象的列表
	 * @return 快捷菜单form对象列表
	 */
	public static List<AcUserShortcutForm> getShortcutFormList(List<Object[]> tempList){
		List<AcUserShortcutForm> result = null;
		if(tempList != null && tempList.size() > 0){
			result = new ArrayList();
			for(Object[] objs : tempList){
				AcUserShortcut shortcut = (AcUserShortcut)objs[0];
				AcMenu menu = (AcMenu)objs[1];
				result.add(convertToForm(shortcut, menu));
			}
		}
		return result;
	}
}
